package eu.ec.ellipcis.integration.ws.client;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.support.MessageBuilder;

import eu.ec.ellipcis.integration.ws.support.CommonConfiguration;

public class TicketWebServiceDomClient {
    private static String bodyTemplate =
            "<TicketRequest xmlns=\"" + CommonConfiguration.NAMESPACE + "\">" +
                    "<description>%s</description>" +
                    "<priority>%s</priority>" +
                    "</TicketRequest>";

    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("client.xml");

        MessageChannel channel = context.getBean("ticketRequests", MessageChannel.class);

        String body = String.format(bodyTemplate, "Message Broker Down", "emergency");
        System.out.println(body);
        MessagingTemplate messagingTemplate = new MessagingTemplate();
        Message<String> soapMessage = MessageBuilder
            .withPayload(body)
            .setCorrelationId(123456789)
            .setHeaderIfAbsent("documentType", "ticketRequestType")
            .build();
        //Message<?> message = messagingTemplate.sendAndReceive(channel, soapMessage);

        messagingTemplate.send(channel, soapMessage);
        //System.out.println(message.getPayload());

    }

}
